package com.habdqn.studentmanager.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import org.apache.commons.lang3.StringEscapeUtils;

/**
 * @author Administrator
 * 
 * 2017年6月9日
 * 
 */
public class XssServletRequest extends HttpServletRequestWrapper{

	public XssServletRequest(HttpServletRequest request) {
		super(request);
	}

	@Override
	public String getParameter(String name) {
		if (null == name) {
			return null;
		}
		
		String parameter = super.getParameter(name);
		
		if (null == parameter) {
			return null;
		}
		
		return StringEscapeUtils.escapeHtml4(parameter.trim());
	}
	
	@Override
	public String[] getParameterValues(String name) {
		if (null == name) {
			return null;
		}
		
		String[] array = super.getParameterValues(name);
		
		if (null == array || 0 == array.length) {
			return array;
		}
		
		for (int i = 0; i < array.length; i++) {
			String parameter = array[i];
			
			if (null != parameter) {
				parameter = parameter.trim();
			}
			
			array[i] = StringEscapeUtils.escapeHtml4(parameter);
		}
		
		return array;
	}
}
